package com.acwing.partition20;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/4/25 16:46
 */
public class AC1921重新排列奶牛 {

    private static final int N = 110;
    private static int[] a = new int[N], b = new int[N], parent = new int[N], size = new int[N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 1; i <= n; i++) a[i] = nextInt();
        for (int i = 1; i <= n; i++) b[nextInt()] = i;
        for (int i = 1; i <= n; i++) {
            parent[i] = i;
            size[i] = 1;
        }
        for (int i = 1; i <= n; i++) {
            int x = a[i], y = a[b[x]], fx = find(x), fy = find(y);
            if (fx != fy) {
                size[fy] += size[fx];
                parent[fx] = fy;
            }
        }
        int ans1 = 0, ans2 = 0;
        for (int i = 1; i <= n; i++) {
            if (parent[i] == i && size[i] > 1) {
                ans2 = Math.max(ans2, size[i]);
                ans1++;
            }
        }
        if (ans1 == 0) ans2 = -1;
        writer.format("%d %d", ans1, ans2);
        writer.flush();
    }

    private static int find(int x) {
        if (x != parent[x]) parent[x] = find(parent[x]);
        return parent[x];
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
